package com.esri.core.internal.tasks.ags.c;

import com.esri.core.geometry.SpatialReference;
import com.esri.core.internal.tasks.TaskListener;
import com.esri.core.io.UserCredentials;
import com.esri.core.map.FeatureResult;
import com.esri.core.map.Field;
import java.util.ArrayList;
import org.codehaus.jackson.JsonParser;
import org.codehaus.jackson.JsonToken;

/* loaded from: classes.dex */
public class g extends com.esri.core.internal.tasks.d<FeatureResult> {
    private static final long serialVersionUID = 1;

    public g(i iVar, String str, UserCredentials userCredentials, TaskListener<FeatureResult> taskListener) {
        super(iVar, str, userCredentials, taskListener);
    }

    public g(i iVar, String str, UserCredentials userCredentials) {
        super(iVar, str, userCredentials);
    }

    @Override // com.esri.core.internal.tasks.a
    /* renamed from: a */
    public FeatureResult execute() throws Exception {
        FeatureResult a;
        AutoCloseable autoCloseable = null;
        try {
            i iVar = (i) this.actionInput;
            StringBuilder sb = new StringBuilder();
            sb.append(this.serviceURL);
            sb.append(iVar.c() ? "/dynamicLayer" : "");
            sb.append("/query");
            JsonParser b = com.esri.core.internal.io.handler.h.b(sb.toString(), this.actionInput.generateRequestParams(), getServiceCredentials());
            if (iVar.t() != null && iVar.t().length > 0) {
                a = com.esri.core.internal.tasks.f.c.a(b);
            } else {
                a = a(b, false, ((i) this.actionInput).a());
            }
            if (b != null) {
                b.close();
            }
            return a;
        } catch (Throwable th) {
            if (0 != 0) {
                autoCloseable.close();
            }
            throw th;
        }
    }

    public static FeatureResult a(JsonParser jsonParser, boolean z, int i) throws Exception {
        SpatialReference spatialReference = null;
        if (com.esri.core.internal.util.d.c(jsonParser)) {
            ArrayList arrayList = new ArrayList();
            ArrayList arrayList2 = new ArrayList();
            String str = null;
            String str2 = null;
            boolean z2 = false;
            while (jsonParser.nextToken() != JsonToken.END_OBJECT) {
                String currentName = jsonParser.getCurrentName();
                jsonParser.nextToken();
                if ("spatialReference".equals(currentName)) {
                    spatialReference = SpatialReference.fromJson(jsonParser);
                } else if ("displayFieldName".equals(currentName)) {
                    str = jsonParser.getText();
                } else if ("exceededTransferLimit".equals(currentName)) {
                    z2 = jsonParser.getBooleanValue();
                } else if ("objectIdFieldName".equals(currentName)) {
                    str2 = jsonParser.getText();
                } else if ("features".equals(currentName)) {
                    if (jsonParser.getCurrentToken() == JsonToken.START_ARRAY) {
                        while (jsonParser.nextToken() != JsonToken.END_ARRAY) {
                            arrayList2.add(a.a(jsonParser, spatialReference, str2));
                        }
                    }
                    com.esri.core.internal.tasks.f.c.a(arrayList2, arrayList);
                } else if ("fields".equals(currentName)) {
                    if (jsonParser.getCurrentToken() == JsonToken.START_ARRAY) {
                        while (jsonParser.nextToken() != JsonToken.END_ARRAY) {
                            Field fromJson = Field.fromJson(jsonParser);
                            arrayList.add(fromJson);
                            if (80 == fromJson.getFieldType()) {
                                str2 = fromJson.getName();
                            }
                        }
                    }
                } else if ("objectIds".equalsIgnoreCase(currentName)) {
                    if (jsonParser.getCurrentToken() == JsonToken.START_ARRAY) {
                        while (jsonParser.nextToken() != JsonToken.END_ARRAY) {
                            arrayList2.add(new a(jsonParser.getLongValue(), null, null, null));
                        }
                    }
                } else {
                    jsonParser.skipChildren();
                }
            }
            return new b(arrayList2, str, str2, arrayList, z2);
        }
        return null;
    }
}
